<template>
    <div class="login-container">
        <div class="login-box">
          <div style="display: flex;
    justify-content: center;
    align-items: center;margin-bottom: 10px;">
            <img style="width: 50px;height: 50px;" src="https://ggbondtech.com/logo.png">
          </div>

            <el-form ref="formRef" :rules="data.rules" :model="data.form" class="login-form">
                <div class="login-title">欢迎登录MBTI职业性格测试系统</div>
                <el-form-item prop="username">
                    <el-input
                        v-model="data.form.username"
                        placeholder="请输入账号"
                        class="login-input"
                        prefix-icon="user"
                    ></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        v-model="data.form.password"
                        placeholder="请输入密码"
                        class="login-input"
                        type="password"
                        show-password
                        prefix-icon="lock"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="login" type="primary" class="login-btn">登 录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script setup>
import request from '@/utils/request';
import { reactive, ref } from 'vue';
import { ElMessage } from 'element-plus'

const data = reactive({
    form: {},
    rules:{
         username: [
            { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
        ]
    }
})

const formRef = ref()
const login = () => {
    formRef.value.validate((valid) => {
        if (valid){
            request.post('/login',data.form).then(res => {
                if (res.code === '200') {
                    //存储后台的用户数据
                    localStorage.setItem('xm-pro-user',JSON.stringify(res.data))//把JSON对象转换为JSON字符串
                    ElMessage.success("登录成功")
                    setTimeout( () => {
                        location.href = '/manager/question'
                    },500)
                } else {
                    ElMessage.error(res.msg)
                }
            })
        }
    })
}

</script>

<style scoped>
.login-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
  background-image: linear-gradient(0, #4298B4, #4298B4);
  background-size: 100% calc((1130 / 1920) * 100vw);
  background-repeat: no-repeat;
  clip-path: polygon(0% 1%, 24% 4%, 60% 0%, 85% 4%, 100% 1%, 100% 100%, 0% 100%);
}

.login-box {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    padding: 40px;
    width: 400px;
}

.login-title {
    font-size: 24px;
    color: #333;
    text-align: center;
    margin-bottom: 30px;
    font-weight: bold;
}

.login-form {
    display: flex;
    flex-direction: column;
}

.login-input {
    margin-bottom: 20px;
}

.login-input :deep(.el-input__inner) {
    height: 45px;
    font-size: 16px;
}

.login-btn {
    width: 100%;
    height: 45px;
    font-size: 16px;
    margin-top: 10px;
  background-color: #f1d93b;
}
</style>
